$(function() {
	validateRule();
	let index = $("#songType-input").val();
	document.getElementById("songType").value = index;

	//打开头像列表
	$("#pic-btn").click(function(){
		layer.open({
			type: 2,
			title:'头像列表',
			content: '/admin/filesPicList.html',
			area: ['480px', '90%'],
			success: function(layero, index){
				//var body = layer.getChildFrame('.ico-list', index);
				//console.log(layero, index);
			}
		});
	});

	//打开歌曲列表
	$("#mp3-btn").click(function(){
		layer.open({
			type: 2,
			title:'歌曲列表',
			content: '/admin/song/filesSongList.html',
			area: ['480px', '90%'],
			success: function(layero, index){
				//var body = layer.getChildFrame('.ico-list', index);
				//console.log(layero, index);
			}
		});
	});

	//打开mv列表
	$("#mv-btn").click(function(){
		layer.open({
			type: 2,
			title:'MV列表',
			content: '/admin/song/filesMvList.html',
			area: ['480px', '90%'],
			success: function(layero, index){
				//var body = layer.getChildFrame('.ico-list', index);
				//console.log(layero, index);
			}
		});
	});

});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update() {
	$.ajax({
		cache : true,
		type : "PUT",
		url : "/song/song",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code === 200) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入名字"
			}
		}
	})
}